//
//  ViewController.m
//  KeychainDemo
//
//  Created by Guo JingRui on 2017/11/23.
//  Copyright © 2017年 Guo JingRui. All rights reserved.
//

#import "ViewController.h"
#import "JRKeychainTool.h"
#import "KeychainViewController.h"

@interface ViewController ()

@property (weak, nonatomic) IBOutlet UITextField *info;
@property (weak, nonatomic) IBOutlet UILabel *infoLab;



@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view, typically from a nib.
    
    self.navigationItem.title = @"钥匙串存取信息";
    
    
    UIBarButtonItem *right = [[UIBarButtonItem alloc]initWithTitle:@"跳转" style:UIBarButtonItemStylePlain target:self action:@selector(goKaychin)];
    self.navigationItem.rightBarButtonItem = right;
    
    self.infoLab.text = [JRKeychainTool readKeychainValue:@"info"];
    
}

- (void)goKaychin
{
    KeychainViewController *keychain = [[KeychainViewController alloc]init];
    [self.navigationController pushViewController:keychain animated:YES];
}

#pragma mark 保存信息
- (IBAction)saveAction:(id)sender {
    [JRKeychainTool saveKeychainValue:self.info.text key:@"info"];
    self.infoLab.text = [JRKeychainTool readKeychainValue:@"info"];
}

#pragma mark 修改信息
- (IBAction)updateAction:(id)sender {
    [JRKeychainTool updateKeychainValue:self.info.text key:@"info"];
    self.infoLab.text = [JRKeychainTool readKeychainValue:@"info"];
}

#pragma mark 删除信息
- (IBAction)deleteAction:(id)sender {
    [JRKeychainTool deleteKeychainValue:@"info"];
    self.infoLab.text = [JRKeychainTool readKeychainValue:@"info"];
}

#pragma mark 读取信息
- (IBAction)getAction:(id)sender {
    
    self.infoLab.text = [JRKeychainTool readKeychainValue:@"info"];
}


@end
